package com.kgc.scd.controller;

import com.kgc.scd.annotation.RequestPermission;
import com.kgc.scd.annotation.RequestUser;
import com.kgc.scd.bean.Collect;
import com.kgc.scd.bean.CollectProducts;
import com.kgc.scd.bean.Foots;
import com.kgc.scd.service.CollectionService;
import com.kgc.scd.util.*;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created On : 2022/6/18.
 * <p>
 * Author     : 15950526365
 * <p>
 * Description: 收藏足迹操作入口
 */
@Slf4j
@RestController
@Api(tags = "11、收藏足迹的操作入口")
public class CollectionController {

    @Autowired(required = false)
    private CollectionService collectionService;
    /*
     * @author : 15950526365
     * @date   : 2022/6/15
     * @param  : [java.lang.String, java.lang.String]
     * @return : com.kgc.scd.util.RequestResult<java.util.Map<java.lang.String,java.lang.Object>>
     * @description : 收藏的添加功能
     */
    @PostMapping("/collections")
    @ApiOperation(value = "收藏的添加功能")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户编号")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "SUCCESS"),
            @ApiResponse(code = 500, message = "FAIL")
    })
    @RequestPermission
    public RequestResult<Map<String, Object>> collections(@RequestUser UserAnno userAnno,
                                                          @RequestParam("proId") String proId) {
        return collectionService.collections(userAnno.getUserId(),proId);
    }

    /**
     * @param : []
     * @return : com.kgc.scd.util.RequestResult<java.util.List<com.kgc.scd.bean.Cart>>
     * @author : 98730
     * @date : 2022/6/10
     * @description : 显示收藏列表，每页3条数据
     */
    @PostMapping("/queryCollection")
    @ApiOperation(value = "查看用户收藏列表", notes = "显示收藏列表，每页3条数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "页码", defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize", value = "页面容量", defaultValue = "3")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "SUCCESS"),
            @ApiResponse(code = 500, message = "FAIL")
    })
    @RequestPermission
    public RequestResult<PageSupport<CollectProducts>> queryCartListByPage(@RequestParam(defaultValue = "1") Integer pageNo,
                                                                           @RequestParam(defaultValue = "3") Integer pageSize,
                                                                           @RequestParam(defaultValue = "0") Integer orderBy,
                                                                           @RequestUser UserAnno userAnno){
        return  collectionService.queryCartListByPage(pageNo,pageSize,userAnno.getUserId(),orderBy);
    }


    /*
     * @author : 15950526365
     * @date   : 2022/6/15
     * @param  : [java.lang.String, java.util.List<java.lang.String>]
     * @return : com.kgc.scd.util.RequestResult<java.lang.String>
     * @description : 批量删除商品
     */
    //@PostMapping("/delCollectList")
    //@ApiOperation(value = "删除用户收藏")
    //@ApiImplicitParams({
    //        @ApiImplicitParam(name = "proIds", value = "商品编号列表"),
    //})
    //@ApiResponses({
    //        @ApiResponse(code = 200, message = "SUCCESS"),
    //        @ApiResponse(code = 500, message = "FAIL")
    //})
    //@RequestPermission
    //public RequestResult<String> delCollectList(@RequestUser UserAnno userAnno,
    //                                            @RequestParam("proIds") List<String> proIds){
    //    return  collectionService.delCollectList(userAnno.getUserId(),proIds);
    //}

    /*
     * @author : 15950526365
     * @date   : 2022/6/15
     * @param  : [java.lang.Integer, java.lang.Integer]
     * @return : com.kgc.scd.util.RequestResult<java.util.Map<java.lang.String,java.lang.Object>>
     * @description : 足迹的添加与查看 对redis 操作大于五条数据进行删除
     */

    @PostMapping("/requestFoot")
    @ApiOperation(value = "足迹的添加")
    @ApiImplicitParams({
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "SUCCESS"),
            @ApiResponse(code = 500, message = "FAIL")
    })
    @RequestPermission
    public RequestResult<List<Foots>> requestFoot(@RequestUser UserAnno userAnno,
                                                  @RequestParam("proId") String proId){
        return  collectionService.requestFoot(userAnno.getUserId(),proId);
    }

    /*
     * @author : 15950526365
     * @date   : 2022/6/15
     * @param  :
     * @return :
     * @description : 足迹功能显示
     */
    @PostMapping("/selectFoots")
    @ApiOperation(value = "足迹功能显示", notes = "支持分页，默认为第一页，每页显示3条数据")
    @RequestPermission
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "页码", defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize", value = "页面容量", defaultValue = "3")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "SUCCESS"),
            @ApiResponse(code = 500, message = "FAIL")
    })
    public RequestResult<PageSupport<Foots>> selectFoots(@RequestParam(defaultValue = "1") Integer pageNo,
                                                         @RequestParam(defaultValue = "3") Integer pageSize,
                                                        @RequestUser UserAnno userAnno){
        return  collectionService.selectFoots(pageNo,pageSize,userAnno.getUserId());
    }



    /**
     * @author : 15950526365
     * @date   : 2022/6/21
     * @param  :
     * @return :
     * @description :  清除足迹
     */
    @PostMapping("/clearnFoot")
    @ApiOperation(value = "足迹清除", notes = "一键全部删除所有足迹")
    @ApiResponses({
            @ApiResponse(code = 200, message = "SUCCESS"),
            @ApiResponse(code = 500, message = "FAIL")
    })
    @RequestPermission
    public RequestResult<Object> clearnFoot(@RequestUser UserAnno userAnno){
        return collectionService.clearFoot(userAnno.getUserId());
    }

    /**
     * @author : 15950526365
     * @date   : 2022/6/21
     * @param  :
     * @return :
     * @description :  清除收藏
     */
    @PostMapping("/clearCollection")
    @ApiOperation(value = "收藏清除", notes = "一键全部删除所有收藏")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户编号"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "SUCCESS"),
            @ApiResponse(code = 500, message = "FAIL")
    })
    @RequestPermission
    public  RequestResult<Object> clearCollection(@RequestUser UserAnno userAnno){
        return  collectionService.clearCollection(userAnno.getUserId());
    }






}
